<?php //get the q parameter from URL
$rid=$_GET["rid"];
$action = $_GET["action"];
$date = date("Y-m-d H:i:s");
$con = mysql_connect('localhost', 'chokecc_davidlu', 'freethechildren');
mysql_query("SET NAMES 'utf8'",$con);
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("chokecc_davidtest", $con);

if($action == "like") {
	$sql="update pw_likes set likes = likes+1 where rid = ".$rid;
}
else {
	$sql="update pw_likes set hates = hates+1 where rid = ".$rid;
}
$result = mysql_query($sql);
//output the response
if(!$result) {
	echo "Database returns an error!";
}
if($action == "like") {
	$sql="select likes from pw_likes where rid = ".$rid;
}
else {
	$sql="select hates from pw_likes where rid = ".$rid;
}
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$icount = $row[0];
echo "(".$icount.")";
mysql_close($con);
?>
